<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        .banner {
            width: 150px;
            height: 300px;
            background-color: lightgreen;
            position: fixed;
            right: 0px;
            top: 200px;
        }
        .banner p {
            width: 15px;
            height: 15px;
            position: absolute;
            top: 0px;
            right: 0px;
        }
    </style>
</head>
<body>
    <div>
        在页面上根据数据，动态创建表格<br>

        var arr = [<br>
        {<br>
            name: 'Jack',<br>
            age: 18,<br>
            gender: '男'<br>
        },{<br>
            name: 'Rose',<br>
            age: 20,<br>
            gender: '女'<br>
        },{<br>
            name: 'Top',<br>
            age: 22,<br>
            gender: '男'<br>
        }<br>
        ]<br><br>
        创建一个表格，展示上面数组中的信息<br>
    </div>
    <div class="banner">
        <p>X</p>
        我是广告
    </div>
    <div>
        <table class="table">

        </table>
    </div>
    <script>
        var arr = [
                    {
                        name: 'Jack',
                        age: 18,
                        gender: '男'
                    },{
                        name: 'Rose',
                        age: 20,
                        gender: '女'
                    },{
                        name: 'Top',
                        age: 22,
                        gender: '男'
                    },{
                        name: 'Rose',
                        age: 20,
                        gender: '女'
                    }
                    ,{
                        name: 'Rose',
                        age: 20,
                        gender: '女'
                    }
                    ,{
                        name: 'Rose',
                        age: 20,
                        gender: '女'
                    }
                ];
        var tableEle = document.querySelector(".table");
        var str = '<tr><td>name</td><td>age</td><td>gender</td></tr>' ;
        for ( var i = 0 ; i < arr.length ; i ++ ) {
            if (i % 2 == 0 ){
                str = str + '<tr style = "background:skyblue;">' ;
            } else {
                str = str + '<tr>' ; 
            }
            for( var key in arr[i] ) {
                str = str + '<td>' + arr[i][key] + '</td>' ; 
            }
            str = str + '</tr>' ; 
        }
        tableEle.innerHTML = str ;
        var pEle = document.querySelector(".banner p");
        pEle.onclick = function (){
            document.querySelector(".banner").style.display = "none";
        }
    </script>
</body>
</html>